<script setup>
import api from '../api/ee_api.js'
import {ref,onMounted} from "vue";
import {ElMessageBox} from "element-plus";
import lodash from 'lodash'
//定义绑定的数据
//表格中的数据
const tableData = ref([]);

const total = ref(0);
const editWinVisible = ref(false);
const addWinVisible = ref(false);
//查询的数据
const searchObj =ref( {
  current: 1,//当前页码
  limit: 10,//每页条数
  reporter_id: '',//查询条件
  event_type: '',
  severity_level: '',
  status: '',
})
const search = async () => {
  var result=await api.page(searchObj.value);//刷新数据
  tableData.value = result.data;
  total.value = result.count;
}
//要修改或者新增的数据
const editObj = ref({});
const addObj = ref({});

onMounted(async ()=>{
  search();
})
//页面加载后挂载的数据

//定义方法
const handleSizeChange = (val) => {
  search.log(searchObj)
  search();
}
const handleCurrentChange = (val) => {
  searchObj.value.current = val;
  search();
}
const editCancel=()=>{
  editObj.value = {};//清空数据
  editWinVisible.value = false;//关闭窗口
}
const editCommit=async () =>{
  await api.edit(editObj.value);//新增或修改
  search();//刷新数据
  editWinVisible.value = false;//关闭窗口
}
const addCancel=()=>{
  addObj.value = {};//清空数据
  addWinVisible.value = false;//关闭窗口
}
const addCommit=async () =>{
  await api.add(addObj.value);//新增或修改
  search();//刷新数据
  addWinVisible.value = false;//关闭窗口
  addObj.value = {};
}

const handleSearch = () => {
  searchObj.value.current = 1;
  search();
}
const handleAdd = (index, row) => {
  addWinVisible.value = true;//显示窗口
  console.log(index, row)//获取当前行数据
}




</script>

<template>
  <!--  查询-->
  <el-form :inline="true" :model="searchObj" class="demo-form-inline" style="margin-top: 10px">
    <el-form-item label="上报居民ID" :label-width="formLabelWidth">
      <el-input v-model="searchObj.reporter_id" autocomplete="off" />
    </el-form-item>
    <el-form-item label="事件类型" :label-width="formLabelWidth">
      <el-select v-model="searchObj.event_type" placeholder="请选择安全等级" style="width: 100px">
        <el-option label="" value="" />
        <el-option label="医疗救助" value="医疗救助" />
        <el-option label="自然灾害" value="自然灾害" />
        <el-option label="安全事故" value="安全事故" />
        <el-option label="治安事故" value="治安事故" />
        <el-option label="家庭变故" value="家庭变故" />
        <el-option label="其他" value="其他" />
      </el-select>
    </el-form-item>
    <el-form-item label="紧急程度" :label-width="formLabelWidth">
      <el-select v-model="searchObj.severity_level" placeholder="请选择紧急程度" style="width: 100px">
        <el-option label="" value="" />
        <el-option label="一般" value="一般" />
        <el-option label="较急" value="较急" />
        <el-option label=紧急 value="紧急" />
        <el-option label="特急" value="特急" />
      </el-select>
    </el-form-item>
    <el-form-item label="处理状态" :label-width="formLabelWidth">
      <el-select v-model="searchObj.status" placeholder="请选择处理状态" style="width: 100px">
        <el-option label="" value="" />
        <el-option label="已上报" value="已上报" />
        <el-option label="已受理" value="已受理" />
        <el-option label="处理中" value="处理中" />
        <el-option label="已解决" value="已解决" />
      </el-select>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleSearch">查询</el-button>
    </el-form-item>
  </el-form>
  <!--  展示-->
  <el-table :data="tableData" style="width: 100%">
    <el-table-column label="事件ID" width="80">
      <template #default="scope">
        <div style="display: flex; align-items: center">
          <span style="margin-left: 10px">{{ scope.row.id }}</span>
        </div>
      </template>
    </el-table-column>
    v<el-table-column label="涉及居民ID" width="80">
    <template #default="scope">
      <el-popover effect="light" trigger="hover" placement="top" width="auto">
        <template #reference>
          <el-tag>{{ scope.row.resident_id }}</el-tag>
        </template>
      </el-popover>
    </template>
  </el-table-column>
    <el-table-column label="上报居民ID" width="80">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #reference>
            <el-tag>{{ scope.row.reporter_id }}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="事件类型" width="80">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #reference>
            <el-tag>{{ scope.row.event_type }}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="发生时间" width="180">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #reference>
            <el-tag>{{ scope.row.event_time }}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="上报时间" width="180">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #reference>
            <el-tag>{{ scope.row.report_time }}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="事件标题" width="80">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #reference>
            <el-tag>{{ scope.row.event_title}}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="发生地点" width="80">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #reference>
            <el-tag>{{ scope.row.location }}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="事件描述" width="180">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #reference>
            <el-tag>{{ scope.row.description }}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="紧急程度" width="80">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #reference>
            <el-tag>{{ scope.row.severity_level }}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="事件状态" width="80">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #reference>
            <el-tag>{{ scope.row.status }}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="处理措施" width="180">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #reference>
            <el-tag>{{ scope.row.response_measure }}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="后续记录" width="180">
      <template #default="scope">
        <el-popover effect="light" trigger="hover" placement="top" width="auto">
          <template #reference>
            <el-tag>{{ scope.row.follow_up_record }}</el-tag>
          </template>
        </el-popover>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
      v-model:current-page="searchObj.current"
      v-model:page-size="searchObj.limit"
      :page-sizes="[10, 20, 30, 40]"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
  />
</template>

<style></style>